<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script>
    function queryData(url) {
        var p=new Promise(function (resolve,reject) {
            var xhr=new XMLHttpRequest()
            xhr.onreadystatechange=function () {
                if (xhr.readyState!=4) return
                if (xhr.readyState==4&&xhr.status==200){
                    // 正常情况
                    resolve(xhr.responseText)
                }else {
                    // 异常情况
                    reject('服务器错误')
                }
            }
            xhr.open('get',url)
            xhr.send(null)
        })
        return p
    }

    var p1=queryData('http://localhost:3000/a1')
    var p2=queryData('http://localhost:3000/a2')
    var p3=queryData('http://localhost:3000/a3')
    // Promise.all([p1,p2,p3]).then(function (result) {
    //     console.log(result)
    // })
    Promise.race([p1,p2,p3]).then(function (result) {
        console.log(result)
    })
</script>
</body>
</html>